# import cv2
# import pytesseract
# import time
# # 指定要识别的语言，可以包括多种语言，以逗号分隔
# languages = 'eng+chi_sim'  # 英文 + 中文（简体）
# """
# 1 3 9 识别效果比较好
#
# """
# for index in range(1, 10):
#     start = time.time()
#     filename1 = 'D:/AI_images/' + str(index) + '.png'
#     image = cv2.imread(filename1)
#     gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#     # 进行其他预处理操作，如降噪和二值化
#     # 识别图片中的文本
#     text = pytesseract.image_to_string(image, lang=languages, config='--psm 3')
#     filename2 = 'D:/AI_images/' + str(index) + '.txt'
#     end = time.time()
#     t = "运行时间:{:.2f}秒".format(end-start)
#     with open(filename2, 'w', encoding='utf-8')as f:
#         f.write(t + '*'*50 + '\n\n' + text)
#     print('type: ', type(text))
#     print('before: ', text)
#     print('*'*60)
#     ' '
#
#     text = text.replace(' ', '')
#     print("after: ", text)

path = "./image_reg/"
def get_request(topic, quantity):
    if topic == 0:
        q_filename = "1.txt"
        a_filename = "1_answer.txt"
    elif topic == 1:
        q_filename = '3.txt'
        a_filename = '3_answer.txt'
    else:
        q_filename = '9.txt'
        a_filename = '9_answer.txt'
    with open(path+q_filename, 'r', encoding='utf-8') as f:
        question = f.read()
    with open(path+a_filename, 'r', encoding='utf-8') as f:
        answer = f.read()
    return [{'question_text': f"{question}", 'answer': f"{answer}"}]

if __name__ == '__main__':
    que = get_request(2, 12)
    print(que)